//这里主要是获取用户的state(状态)
function getState(){
    var username = document.getElementById("username").value;
    var password = document.getElementById("password").value;
    var inputCode = document.getElementById("validatecode").value;
	// 1.获取异步交互对象
	var xmlHttp = createXMLHttpRequest();
    //打开
    xmlHttp.open("GET","/newshop/getState?username="+username+"&password="+password+"&inputCode="+inputCode,true);

    //设置类型（一定要设置）
    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    //发送
    xmlHttp.send("username="+username+"&password="+password+"&inputCode="+inputCode+"&time="+new Date());
    //设置监听
    xmlHttp.onreadystatechange=function () {
        if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
            if(xmlHttp.responseText == 1){
                document.getElementById("state").value = xmlHttp.responseText;
                window.location.href = "/newshop/index.jsp";
            }else{
                document.getElementById("u").innerHTML = xmlHttp.responseText;
            }
        }
    }
}

// 创建XMLHttpRequest对象
function createXMLHttpRequest() {
	try {
		return new XMLHttpRequest();
	} catch (e) {
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("你用什么浏览器呢？");
				throw e;
			}
		}
	}
};

//登录表单的非空校验
function check(){
	var username = document.getElementById("username").value;
	if(username == null || username ==""){
		alert("用户名不能为空");
		return false;
	}
	var password = document.getElementById("password").value;
	if(password == null || password ==""){
		alert("密码不能为空");
		return false;
	}
	var validatecode = document.getElementById("validatecode").value;
	if(validatecode == null || validatecode ==""){
		alert("验证码不能为空");
		return false;
	}

    return getState();
}

//切换验证码
function changecode(){
    var img = document.getElementById("validateimage");
    img.src = "${pageContext.request.contextPath}/codeGenerate?a="+new Date().getTime();
}



